#include "display.h"
#include "ui_display.h"

display::display(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::display)
{
    ui->setupUi(this);
    setFixedSize(400, 300);
}

display::~display()
{
    delete ui;
}

void display::set_type(int a)
{
    type=a;
}

void display::on_pushButton_clicked()  //display按钮点击触发
{
    QSqlQuery query1,query2;
    if(type==0)  //显示所有学生信息
    {
        query1.exec("select * from student");
        while(query1.next())
        {
            QString sno = query1.value(0).toString();
            QString name = query1.value(1).toString();
            QString collage = query1.value(2).toString();
            QString temp=sno+"  "+name+"  "+collage+"\n";
            ui->textEdit->setText(ui->textEdit->toPlainText().append(temp));
        }
    }
    else if(type==1)  //显示所有老师信息
    {
        query1.exec("select * from teacher");
        query1.next();
        while(query1.next())
        {
            QString tno = query1.value(0).toString();
            QString tname = query1.value(1).toString();
            QString collage = query1.value(2).toString();
            query2.exec("select cname from course where cno='"+query1.value(4).toString()+"'");
            query2.next();
            QString course = query2.value(0).toString();
            QString temp=tno+"  "+tname+"  "+collage+"  "+course+"\n";
            ui->textEdit->setText(ui->textEdit->toPlainText().append(temp));
        }
    }
    else if(type==2)  //显示所有课程信息
    {
        query1.exec("select * from course");
        while(query1.next())
        {
            QString cno =query1.value(0).toString();
            QString cname = query1.value(1).toString();
            QString college = query1.value(2).toString();
            QString captive = query1.value(3).toString();
            QString surplus = query1.value(4).toString();
            QString temp=cno+"  "+cname+"  "+college+"  "+captive+"  "+surplus+"\n";
            ui->textEdit->setText(ui->textEdit->toPlainText().append(temp));
        }
    }

}

void display::on_pushButton_2_clicked()  //back按钮点击触发
{
    ui->textEdit->setText("");  //将显示信息清空
    this->close();
}
